package com.tanhua.server.interceptor;

/**
 * @author ck
 * @date 2021/11/11 15:42
 */

import com.tanhua.model.domain.User;

/**
 * 工具类：实现向threadlocal存储数据的方法
 */
public class UserHolder {
    private static ThreadLocal<User> threadLocal = new ThreadLocal();

    //将用户对象，存入threadlocal
    public static void set(User user){
        threadLocal.set(user);
    }
    //从当前线程：获取用户对象
    public static User get(){
        return threadLocal.get();
    }


    //获取当前用户对象的id
    public static Long getUserId(){
        return threadLocal.get().getId();
    }

    //获取当前用户对象的手机号码
    public  static String getMobile(){
        return threadLocal.get().getMobile();
    }

    public static void remove(){
        threadLocal.remove();
    }
}
